import 'package:eshi/app/Extension.dart';
import 'package:eshi/app/shi/data/History.dart';
import 'package:eshi/app/shi/data/parse/TxtTabPointParser.dart';
import 'package:eshi/app/shi/data/parse/TxtYearDataPointParser.dart';
import 'package:eshi/app/shi/data/tabtxt_history.dart';

 class TxtPointParser {
  History history;
  TxtPointParser(this.history);

  void initData(String data){}

  static void parse(text, TabTxtHistory tabTxtHistory,{String name=""}) {
    var parser;
    if(RegExp(r"\(\S+ \d{4},\d{4}\)").hasMatch(text)){
      parser = TxtYearDataPointParser(tabTxtHistory,Type.extend);  
    }else if(RegExp(r"^\d+[:：]").hasMatch(text)){
      parser = TxtYearDataPointParser(tabTxtHistory,Type.head);  
    }else {
      parser = TxtTabPointParser(tabTxtHistory);
      tabTxtHistory.initDataByTableText(text,name:name,createPointBefore: (p){
          parser.onPointCreate(p);
      });
      //序号信息
      if(tabTxtHistory.data.isNotEmpty && tabTxtHistory.data.last.startTime==0){
        tabTxtHistory.data.forEachIndexed((i,d)  {
          d.startTime=i+1;
          d.endTime=d.startTime;
        });
        tabTxtHistory.endTime =tabTxtHistory.data.length+1;
      }
    }
    parser.initData(text);
  }

}